package com.example.project.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.example.project.entity.SystemConfig;

/**
 * 参数配置 数据层
 * 
 * @author ruoyi
 */
@Mapper
public interface SystemConfigMapper {

	/**
	 * 查询参数配置信息
	 * 
	 * @param config 参数配置信息
	 * @return 参数配置信息
	 */
	@Select("<script>select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark from t_system_config"
			+ "<where>" + "<if test=\"configId != null\">and config_id = #{configId}</if>"
			+ "<if test=\"configKey != null and configKey != ''\">and config_key = #{configKey}</if>"
			+ "</where></script>")
	public SystemConfig selectConfig(SystemConfig config);

	/**
	 * 通过ID查询配置
	 * 
	 * @param configId 参数ID
	 * @return 参数配置信息
	 */
	@Select("select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark from t_system_config where config_id = #{configId}")
	public SystemConfig selectConfigById(Long configId);

	/**
	 * 查询参数配置列表
	 * 
	 * @param config 参数配置信息
	 * @return 参数配置集合
	 */
	@Select("<script>select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark from t_system_config"
			+ "<where>"
			+ "<if test=\"configName != null and configName != ''\">AND config_name like concat('%', #{configName}, '%')</if>"
			+ "<if test=\"configType != null and configType != ''\">AND config_type = #{configType}</if>"
			+ "<if test=\"configKey != null and configKey != ''\">AND config_key like concat('%', #{configKey}, '%')</if>"
			+ "<if test=\"params != null and params.beginTime != null and params.beginTime != ''\">and date_format(create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')</if>"
			+ "<if test=\"params != null and params.endTime != null and params.endTime != ''\">and date_format(create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')</if>"
			+ "</where></script>")
	public List<SystemConfig> selectConfigList(SystemConfig config);

	/**
	 * 根据键名查询参数配置信息
	 * 
	 * @param configKey 参数键名
	 * @return 参数配置信息
	 */
	@Select("select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark from t_system_config where config_key = #{configKey} limit 1")
	public SystemConfig checkConfigKeyUnique(String configKey);

	/**
	 * 新增参数配置
	 * 
	 * @param config 参数配置信息
	 * @return 结果
	 */
	@Insert("<script>insert into t_system_config ("
			+ "<if test=\"configName != null and configName != ''\">config_name,</if>"
			+ "<if test=\"configKey != null and configKey != ''\">config_key,</if>"
			+ "<if test=\"configValue != null and configValue != ''\">config_value,</if>"
			+ "<if test=\"configType != null and configType != ''\">config_type,</if>"
			+ "<if test=\"createBy != null and createBy != ''\">create_by,</if>"
			+ "<if test=\"remark != null and remark != ''\">remark,</if>" + "create_time" + ") values ("
			+ "<if test=\"configName != null and configName != ''\">#{configName},</if>"
			+ "<if test=\"configKey != null and configKey != ''\">#{configKey},</if>"
			+ "<if test=\"configValue != null and configValue != ''\">#{configValue},</if>"
			+ "<if test=\"configType != null and configType != ''\">#{configType},</if>"
			+ "<if test=\"createBy != null and createBy != ''\">#{createBy},</if>"
			+ "<if test=\"remark != null and remark != ''\">#{remark},</if>" + "sysdate()" + ")</script>")
	public int insertConfig(SystemConfig config);

	/**
	 * 修改参数配置
	 * 
	 * @param config 参数配置信息
	 * @return 结果
	 */
	@Update("<script>update t_system_config" + "<set>"
			+ "<if test=\"configName != null and configName != ''\">config_name = #{configName},</if>"
			+ "<if test=\"configKey != null and configKey != ''\">config_key = #{configKey},</if>"
			+ "<if test=\"configValue != null and configValue != ''\">config_value = #{configValue},</if>"
			+ "<if test=\"configType != null and configType != ''\">config_type = #{configType},</if>"
			+ "<if test=\"updateBy != null and updateBy != ''\">update_by = #{updateBy},</if>"
			+ "<if test=\"remark != null\">remark = #{remark},</if>" + "update_time = sysdate()" + "</set>"
			+ "where config_id = #{configId}</script>")
	public int updateConfig(SystemConfig config);

	/**
	 * 删除参数配置
	 * 
	 * @param configId 参数主键
	 * @return 结果
	 */
	@Delete("delete from t_system_config where config_id = #{configId}")
	public int deleteConfigById(Long configId);

	/**
	 * 批量删除参数配置
	 * 
	 * @param configIds 需要删除的数据ID
	 * @return 结果
	 */
	@Delete("<script>delete from t_system_config where config_id in"
			+ "<foreach item=\"configId\" collection=\"array\" open=\"(\" separator=\",\" close=\")\">" + "#{configId}"
			+ "</foreach></script>")
	public int deleteConfigByIds(String[] configIds);
}